added SSCLI 1.0
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2010 / CSImageFullScreenSlideShow / ReadMe.txt
blobd0cc7082bb06582e0ab3b79d209fa23ecbad181c
1 =============================================================================
2        Windows APPLICATION: CSImageFullScreenSlideShow Overview
3 =============================================================================
5 /////////////////////////////////////////////////////////////////////////////
6 Summary:
8 The sample demonstrates how to display image slideshow in a Windows Forms 
9 application.  It also shows how to enter the full screen mode to slide-show 
10 images. 
13 /////////////////////////////////////////////////////////////////////////////
14 Demo:
16 Step1. Build and run the sample project in Visual Studio 2010. 
18 Step2. Prepare some image files.  Click the "Open Folder..." button and 
19        select the path which includes image files. 
21 Step3. Click "Previous" button and "Next" button to make image files 
22        displayed in order.
24 Step4. Left-click the "Settings" button and select the internal between the 
25        displayed image files for Timer control in order to display them 
26        with a fixed interval time. Finally, left-click the "Start Slideshow"
27            button to make the image files displayed one by one.
29 Step5. Left-click the "Full Screen" button to display images in the full 
30 screen mode.  Press the "ESC" key to leave the full screen mode.
33 /////////////////////////////////////////////////////////////////////////////
34 Implementation:
36 1. When user selects the root folder of image files, the sample enumerates 
37    the image files in the folder using the stack-based iteration method 
38    demonstrated in this MSDN article: 
39    http://msdn.microsoft.com/en-us/library/bb513869.aspx
40    The sample does not use 
41         Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);
42    to enumerate the files because it will abort when the user does not have 
43    access permissions for certain directories or files in the root folder.
45         public static string[] GetFiles(string path, string searchPattern)
46         {
47             string[] patterns = searchPattern.Split(';');
48             List<string> files = new List<string>();
49             foreach (string filter in patterns)
50             {
51                 // Iterate through the directory tree and ignore the 
52                 // DirectoryNotFoundException or UnauthorizedAccessException 
53                 // exceptions. 
54                 // http://msdn.microsoft.com/en-us/library/bb513869.aspx
56                 // Data structure to hold names of subfolders to be
57                 // examined for files.
58                 Stack<string> dirs = new Stack<string>(20);
60                 if (!Directory.Exists(path))
61                 {
62                     throw new ArgumentException();
63                 }
64                 dirs.Push(path);
66                 while (dirs.Count > 0)
67                 {
68                     string currentDir = dirs.Pop();
69                     string[] subDirs;
70                     try
71                     {
72                         subDirs = Directory.GetDirectories(currentDir);
73                     }
74                     // An UnauthorizedAccessException exception will be thrown 
75                     // if we do not have discovery permission on a folder or 
76                     // file. It may or may not be acceptable to ignore the 
77                     // exception and continue enumerating the remaining files 
78                     // and folders. It is also possible (but unlikely) that a 
79                     // DirectoryNotFound exception will be raised. This will 
80                     // happen if currentDir has been deleted by another 
81                     // application or thread after our call to Directory.Exists. 
82                     // The choice of which exceptions to catch depends entirely 
83                     // on the specific task you are intending to perform and 
84                     // also on how much you know with certainty about the 
85                     // systems on which this code will run.
86                     catch (UnauthorizedAccessException)
87                     {
88                         continue;
89                     }
90                     catch (DirectoryNotFoundException)
91                     {
92                         continue;
93                     }
95                     try
96                     {
97                         files.AddRange(Directory.GetFiles(currentDir, filter));
98                     }
99                     catch (UnauthorizedAccessException)
100                     {
101                         continue;
102                     }
103                     catch (DirectoryNotFoundException)
104                     {
105                         continue;
106                     }
108                     // Push the subdirectories onto the stack for traversal.
109                     // This could also be done before handing the files.
110                     foreach (string str in subDirs)
111                     {
112                         dirs.Push(str);
113                     }
114                 }
115             }
117             return files.ToArray();
118         }
120 2. The sample displays the images in a PictureBox. 
122         /// <summary>
123         /// Show the image in the PictureBox.
124         /// </summary>
125         public static void ShowImage(string path, PictureBox pct)
126         {
127             pct.ImageLocation = path;
128         }
130         /// <summary>
131         /// Show the previous image.
132         /// </summary>
133         private void ShowPrevImage()
134         {
135             ShowImage(this.imageFiles[(--this.selected) % this.imageFiles.Length], this.pictureBox);
136         }
138         /// <summary>
139         /// Show the next image.
140         /// </summary>
141         private void ShowNextImage()
142         {
143             ShowImage(this.imageFiles[(++this.selected) % this.imageFiles.Length], this.pictureBox);
144         }
146    A timer is used to automatically slideshow the images.
148         /// <summary>
149         /// Show the next image at every regular intervals.
150         /// </summary>
151         private void timer_Tick(object sender, EventArgs e)
152         {
153             ShowNextImage();
154         }
156 2. To slide-show images in the full-screen mode, the sample provides a helper 
157    class 'FullScreen'.  FullScreen.cs contains two public methods: 
158    
159         EnterFullScreen - used to make a Windows Form display in the full screen.
160         LeaveFullScreen - used to restore a Windows Form to its original state.
162         /// <summary>
163         /// Maximize the window to the full screen.
164         /// </summary>
165         public void EnterFullScreen(Form targetForm)
166         {
167             if (!IsFullScreen)
168             {
169                 Save(targetForm);  // Save the original form state.
171                 targetForm.WindowState = FormWindowState.Maximized;
172                 targetForm.FormBorderStyle = FormBorderStyle.None;
173                 targetForm.TopMost = true;
174                 targetForm.Bounds = Screen.GetBounds(targetForm);
176                 IsFullScreen = true;
177             }
178         }
180         /// <summary>
181         /// Leave the full screen mode and restore the original window state.
182         /// </summary>
183         public void LeaveFullScreen(Form targetForm)
184         {
185             if (IsFullScreen)
186             {
187                 // Restore the original Window state.
188                 targetForm.WindowState = winState;
189                 targetForm.FormBorderStyle = brdStyle;
190                 targetForm.TopMost = topMost;
191                 targetForm.Bounds = bounds;
193                 IsFullScreen = false;
194             }
195         }
198 /////////////////////////////////////////////////////////////////////////////
199 References:
201 How to: Iterate Through a Directory Tree (C# Programming Guide)
202 http://msdn.microsoft.com/en-us/library/bb513869.aspx
204 Screen.GetBounds Method 
205 http://msdn.microsoft.com/en-us/library/system.windows.forms.screen.getbounds.aspx
208 /////////////////////////////////////////////////////////////////////////////